#!/bin/bash
## Platform:All Linux Based Platform
## author:Long Tao
## version:1.0
## description:This is quwan project start script
## Company:QuDan
echo '================开始启动项目==================='
# 镜像仓库
IMAGE_DEPOSITORY=ccr.ccs.tencentyun.com/qudan/qudan
# username
DEPOSITORY_USERNAME=100022109603
# password
DEPOSITORY_PASSWORD=qudan@2021
base_dir=$PWD
IMAGE_TAG=quwan_test
app_name=quwan_test
# 端口
port=8083
echo "当前目录：" "$base_dir"

# 进度条
function pull_sleep() {
  for ((i=0;$i<=20;i++)) ;
  do
    let jinshu=$i*5
    printf "[%-20s]%d%%\r" $b $jinshu
    sleep 0.2
    b=#$b
  done
  echo "拉取镜像完成"
}
docker build -t "$IMAGE_DEPOSITORY":"$IMAGE_TAG" .
# 登录
docker login --username="$DEPOSITORY_USERNAME" --password="$DEPOSITORY_PASSWORD" "$IMAGE_DEPOSITORY"
# push
docker push "$IMAGE_DEPOSITORY":"$IMAGE_TAG"
echo '================正在拉取镜像==================='
#docker login --username="$DEPOSITORY_USERNAME" --password="$DEPOSITORY_PASSWORD" "$IMAGE_DEPOSITORY"
docker pull "$IMAGE_DEPOSITORY":"$app_name"

pull_sleep
# 登出镜像仓库
#docker logout "$IMAGE_DEPOSITORY"
#
## 启动镜像
echo '================启动docker==================='
#docker run --name "$app_name" -d -p "$port":"$port" -v /home/app/jar/"$app_name"/:/tmp/ "$IMAGE_DEPOSITORY":"$app_name"
docker run -e JAVA_OPTS="-Xmx2688M -Xms2688M -Xmn960M -XX:MaxMetaspaceSize=256M -XX:MetaspaceSize=256M" -e ACTIVE="test" \
--name "$app_name" -d -p "$port":"$port" -v /home/app/jar/"$app_name":/tmp  -v /etc/localtime:/etc/localtime \
-v /data/project/quwan/log:/data/project/quwan/log "$IMAGE_DEPOSITORY":"$app_name"
